home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
asmbler.arc
/
FIND.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-11-19
|
10KB
|
433 lines
CR EQU 13
LF EQU 10
ASSUME CS:FINDC,DS:FINDC
FINDC SEGMENT PARA PUBLIC 'CODE'
DB "MAUlloa/Microsoft/V126"
COLON DB ':',' ' ; 16
LINSTR DB '[' ; 18
INTSTR DB 8 DUP (0) ; 19
NOTFLG DB ; 21
CNTFLG DB ; 22
NUMFLG DB ; 23
DB 0,0 ; 24,25
PCOUNT DW ; 26
MCOUNT DW ; 28
FINDF PROC FAR
FIND: MOV AH,30H ; GET DOS VERSION
INT 21H
CMP AL,2
JGE CONT
PUSH CS
POP DS
MOV DX,OFFSET BADDOS
MOV AH,09H ; PRINT STRING
INT 21H
PUSH ES
XOR AX,AX
PUSH AX
RET
FINDF ENDP
ASSUME CS:FINDC,DS:FINDC
FINDN PROC NEAR
CONT: PUSH CS
POP ES
MOV SI,81H
CALL SKIPSP
OR BX,BX
JZ HAVEPARAM
CNTERR: MOV DX,OFFSET NUMERR
MOV CL,CS:NUMLEN
CALL WRITEDSERR
MOV AL,2
JMP ERREXIT
HAVEPARAM:
MOV AH,37H ; INTERNAL CALL GET SWITCHAR
MOV AL,0 ; 1 = SET SWITCHAR ??
INT 21H
PUSH DX
SCANSWITCH:
LODSB
CMP AL,' '
JZ MORESP
CMP AL,CR
JZ CNTERR
POP DX
CMP AL,DL
JNZ SCANPAT
PUSH DX
LODSB
CMP AL,' '
JZ MORESP
CMP AL,CR
JZ CNTERR
CALL LCUC
MOV BX,OFFSET NOTFLG
CMP AL,'V'
JZ SETNOT
CMP AL,'C'
JZ SETCNT
CMP AL,'N'
JZ SETNUM
MOV ES:PATTRN[0],AL
MOV DX,OFFSET PRMERR
MOV CL,CS:PRMLEN
CALL WRITEDSERR
MOV DX,OFFSET PATTRN
MOV CX,1
CALL WRITEDSERR
MOV DX,OFFSET CRLF
MOV CX,2
CALL WRITEDSERR
JMP SCANSWITCH
SETNOT: MOV DI,0
JMP SHORT SETFLG
SETCNT: MOV DI,1
JMP SHORT SETFLG
SETNUM: MOV DI,2
SETFLG: MOV ES:BYTE PTR [BX+DI],-1
JMP SCANSWITCH
MORESP: DEC SI
CALL SKIPSP
OR BX,BX
JZ SCANSWITCH
JMP CNTERR
SCANPAT:
CMP AL,'"'
JNZ NOPAT
MOV DI,OFFSET PATTRN
XOR CX,CX
PATCH: LODSB
CMP AL,CR
JNZ STLPAT
NOPAT: MOV DX,OFFSET SYNERR
MOV CL,CS:SYNLEN
CALL WRITEDSERR
MOV AL,2
JMP ERREXIT
STLPAT: CMP AL,'"'
JNZ STOCH
LODSB
CMP AL,'"'
JZ STOCH
DEC SI
MOV ES:PATLEN,CX
OR CX,CX
JNZ HAVPAT
MOV AL,1
JMP ERREXIT
STOCH: STOSB
INC CX
JMP PATCH
HAVPAT: CALL SKIPSP
OR BX,BX
JZ HAVFIL
PUSH CS
POP DS
MOV AX,0
JMP DOREAD
HAVFIL: CALL CLRCNT
MOV DI,OFFSET FILNAM
XOR CX,CX
FILCH: LODSB
CMP AL,' '
JZ FILEND
CMP AL,CR
JZ FILEND
STOSB
INC CX
JMP FILCH
FILEND: DEC SI
MOV ES:BYTE PTR [DI],0
PUSH SI
PUSH DS
MOV ES:FILLEN,CX
PUSH CS
POP DS
MOV DX,OFFSET FILNAM
MOV AH,3DH ; OPEN FILE
MOV AL,0
INT 21H
JNB FILOPN
JMP BADFIL
FILOPN: PUSH AX
MOV DX,OFFSET SEPLIN
MOV CL,CS:SEPLEN
XOR CH,CH
CALL WRITESTR
MOV DX,OFFSET FILNAM
MOV CX,FILLEN
CALL WRITESTR
CMP CNTFLG,-1
JZ NOCRLF
MOV DX,OFFSET CRLF
MOV CX,2
CALL WRITESTR
NOCRLF: POP AX
DOREAD: MOV BX,AX
NXTREAD:MOV DX,OFFSET BUFFER
MOV CX,4096
MOV AH,3FH ; READ FILE
INT 21H
JNB DIDREAD
JMP BADREAD
DIDREAD:OR AX,AX
JNZ GREPBUF
CMP CNTFLG,-1
JNZ NOCNT
CALL WRITECNT
NOCNT: CMP BX,0
JNZ DOCLOSE
JMP NRMEXIT
DOCLOSE:MOV AH,3EH ; CLOSE FILE
INT 21H
JMP NXTFIL
GREPBUF:PUSH BX
MOV BP,OFFSET BUFFER
MOV DI,AX
CMP AX,4095
JG NOPATCH
MOV BX,BP
CMP BYTE PTR [BX+DI-01],LF
JZ NOPATCH
MOV BYTE PTR [BX+DI],CR
INC DI
MOV BYTE PTR [BX+DI],LF
INC DI
NOPATCH:PUSH DI
PUSH BP
MOV DX,PATLEN
DEC DX
NXTSCN: INC MCOUNT
POP BP
MOV DI,BP
POP CX
MOV BX,CX
MOV AL,LF
JCXZ NOFULLN
REPNZ SCASB
JNZ NOFULLN
PUSH CX
PUSH DI
MOV CX,DI
SUB CX,BP
MOV BX,CX
DEC CX
DEC CX
JCXZ NOTFND
MOV DI,BP
SAMLN: MOV SI,OFFSET PATTRN
LODSB
REPNZ SCASB
JNZ NOTFND
CMP CX,DX
JB NOTFND
PUSH DI
PUSH CX
MOV CX,DX
JCXZ DIDFND
REPZ CMPSB
JZ DIDFND
POP CX
POP DI
JMP SAMLN
DIDFND: POP AX
POP AX
CMP NOTFLG,-1
JNZ NEGNOT
JMP NXTSCN
NOTFND: CMP NOTFLG,-1
JNZ NXTSCN
NEGNOT: CMP CNTFLG,-1
JNZ NOCOUNT
INC PCOUNT
JMP NXTSCN
NOCOUNT:PUSH DX
CMP NUMFLG,-1
JNZ NOLNNUM
CALL WRITELNNUM
NOLNNUM:MOV DX,BP
MOV CX,BX
CALL WRITESTR
POP DX
JMP NXTSCN
NOFULLN:MOV DX,BX
POP BX
OR DX,DX
JZ WHATISTHIS
NEG DX
MOV CX,-1
MOV AL,1
MOV AH,42H ; LSEEK
INT 21H
JB BADREAD
WHATISTHIS:
JMP NXTREAD
ASSUME CS:FINDC
BADREAD:
CMP BX,0
JZ NRMEXIT
MOV AH,3EH ; CLOSE FILE
INT 21H
MOV DX,OFFSET RDDERR
MOV CL,CS:RDDLEN
JMP DOWRITE
BADFIL: MOV DX,OFFSET FNDERR
MOV CL,CS:FNDLEN
DOWRITE:CALL WRITEERR
CALL WRITEFIL
NXTFIL: POP DS
POP SI
CALL SKIPSP
OR BX,BX
JNZ NRMEXIT
JMP HAVFIL
NRMEXIT:MOV AL,0
ERREXIT:MOV AH,4CH ; EXIT
INT 21H
SKIPSP: CLD
XOR BX,BX
HAVESP: LODSB
CMP AL,' '
JZ HAVESP
CMP AL,CR
JNZ NOCR
MOV BX,AX
NOCR: DEC SI
RET
CLRCNT: MOV ES:BYTE PTR PCOUNT,0
MOV ES:BYTE PTR MCOUNT,0
RET
WRITECNT:
PUSH BX
CMP BX,0
JZ NOCOLON
MOV DX,OFFSET COLON
MOV CX,2
CALL WRITESTR
NOCOLON:MOV AX,PCOUNT
MOV DI,OFFSET INTSTR
CALL WRITEINT
MOV DX,OFFSET INTSTR
CALL WRITESTR
MOV DX,OFFSET CRLF
MOV CX,2
CALL WRITESTR
POP BX
RET
WRITELNNUM:
PUSH BX
PUSH DX
MOV AX,MCOUNT
MOV DI,OFFSET INTSTR
CALL WRITEINT
MOV BYTE PTR [DI],']'
INC CX
INC CX
MOV DX,OFFSET LINSTR
CALL WRITESTR
POP DX
POP BX
RET
WRITESTR:
MOV BX,1
MOV AH,40H ; WRITE FILE
INT 21H
RET
WRITEINT:
MOV BX,10
XOR CX,CX
INTDIV: INC CX
CMP AX,BX
JB INTDONE
XOR DX,DX
DIV BX
ADD DL,'0'
PUSH DX
JMP INTDIV
INTDONE:ADD AL,'0'
PUSH AX
MOV BX,CX
INTSTO: POP AX
STOSB
LOOP INTSTO
MOV CX,BX
RET
WRITEFIL:
MOV DX,OFFSET FILNAM
MOV CX,FILLEN
CALL WRITEERR
MOV DX,OFFSET CRLF
MOV CX,2
CALL WRITEERR
RET
WRITEDSERR:
PUSH DS
PUSH CS
POP DS
CALL WRITEERR
POP DS
RET
WRITEERR:
XOR CH,CH
MOV BX,2
MOV AH,40H ; WRITE FILE
INT 21H
RET
LCUC: CMP AL,'a'
JB OK
CMP AL,'z'
JG OK
AND AL,NOT 20H
OK: RET
PATLEN DW ; 0332
PATTRN DB 128 DUP (0) ; 0334
FILLEN DW ; 03B4
FILNAM DB 65 DUP (0) ; 03B6
BUFFER DB 4096 DUP (0) ; 03F7
DB 9 DUP (0)
BADDOS DB "Incorrect DOS version$" ; 00
CRLF DB CR,LF ; 16
NUMERR DB "FIND: Invalid number of parameters",CR,LF ; 18
NUMLEN DB NUMLEN-NUMERR ; 3C
SYNERR DB "FIND: Syntax error",CR,LF ; 3D
SYNLEN DB SYNLEN-SYNERR ; 51
FNDERR DB "FIND: File not found " ; 52
FNDLEN DB FNDLEN-FNDERR ; 67
RDDERR DB "FIND: Read error in " ; 68
RDDLEN DB RDDLEN-RDDERR ; 7C
PRMERR DB "FIND: Invalid Parameter " ; 7D
PRMLEN DB PRMLEN-PRMERR ; 95
SEPLIN DB CR,LF,"---------- " ; 96
SEPLEN DB SEPLEN-SEPLIN ; A3
FINDN ENDP
FINDC ENDS
FINDS SEGMENT STACK
DB 256 DUP (?)
FINDS ENDS
END FIND